﻿@{
	ViewBag.Title = "CBGUrl_Index";
	Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="layuimini-container">
	<div class="layuimini-main">

		@* 搜索信息 *@
		<fieldset class="table-search-fieldset layui-hide" id="searchField">
			<div>
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<div class="layui-input-inline">
								<input type="text" name="keyword" autocomplete="off" placeholder="请输入关键词" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">点开状态:</label>
							<div class="layui-input-block">
								<select id="open_State" name="open_State" lay-filter="open_State" lay-search>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>
		@* 数据表格顶部按钮 *@
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container" id="toolbar">
				<button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
				<button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
				<button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
			</div>
		</script>
		@* 行按钮 *@
		<script type="text/html" id="currentTableBar">
			<a id="NF-delete" authorize class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
		</script>
		@* 数据表格 *@
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
	</div>
</div>

<script type="text/javascript">
	layui.use(['jquery', 'form', 'table', 'common', 'layer', 'optimizeSelectOption', 'commonTable','laydate'], function () {
		var $ = layui.jquery,
			laydate=layui.laydate,
			form = layui.form,
			table = layui.table,
			layer = layui.layer,
			commonTable = layui.commonTable,
			common = layui.common;
		//权限控制(js是值传递)
		currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
		toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
		//行点击事件监听，控制按钮显示
		var oneList = ["NF-delete","NF-edit"];//选择1条显示
		var morerList = ["NF-delete"];//选中1条以上显示
		//commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList, morerList); //单选框
		commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, morerList); //多选框
		// 数据表格
		commonTable.rendertable({
			elem: '#currentTableId',
			id: 'currentTableId',
			url: '/STZBManage/User/Get_CBGUrl_GridJson',
			filter: {
				clearFilter: false
			},
			limit:50, //默认显示20条数据
			cols: [[
				{ type: "checkbox", width: 50, fixed: 'left'},
				{ field: 'Url', title: '藏宝阁Url', minWidth: 280, sort: true, filter: true },
				{ field: 'Open_State', title: '点开状态', width: 120, sort: true, filter: true,
					templet: function (d) {
						//Open_State：字典分类的ID
						return top.clients.dataItems["Open_State"][d.Open_State+2] == undefined ? d.Open_State : top.clients.dataItems["Open_State"][d.Open_State+2];
					}
				},
				{ field: 'Crawl_Time', title: '爬取时间', width: 160, sort: true , filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }},
				{ field: 'CreateTime', title: '创建时间', width: 160, sort: true , filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }},
				{ title: '操作', width: 80, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
			]]
		});
		wcLoading.close(); //关闭加载窗

		//初始化
		$(function(){
			initControl();
			form.render();
		});

		//初始化点开状态下拉列表数据
		function initControl(){
			 //绑定数据源
			//类型为下拉框时
			$("#open_State").bindSelect({
				data: top.clients.dataItems["Open_State"], //Open_State：字典分类ID
				id: ""
			});
		}

		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			//执行搜索重载
			commonTable.reloadtable({
				elem: 'currentTableId',
				curr: 1, //页数
				where: { //参数
					keyword: data.field.keyword,
					open_State:data.field.open_State
				}
			});
			return false;
		});

		//行按钮监听事件
		table.on('tool(currentTableFilter)', function (obj) {
			var id = obj.data.Id;

			if (obj.event === 'delete') { //删除按钮
				common.deleteForm({
					url: "/STZBManage/User/Delete_CBGUrl",
					param: { ids: id },
					success: function () {
						obj.del();
					}
				});
			}
			return false;
		});

		//数据表格顶部按钮监听事件
		table.on('toolbar(currentTableFilter)', function (obj) {
			var data = table.checkStatus('currentTableId').data;
			var id = data.length > 0 ?data[0].Id:null;
			 if (obj.event === 'delete') { //删除按钮
				if (data.length == 0) {
					common.modalMsg("未选中数据", "warning");
					return false;
				}
				var ids = [];
				for (var i = 0; i < data.length; i++) {
					ids.push(data[i].Id);
				}
				common.deleteForm({
					url: "/STZBManage/User/Delete_CBGUrl",
					param: { ids: ids.join(',') },
					success: function () {
						common.reload('data-search-btn');
					}
				});
			}
			else if(obj.event === 'add'){ //新增
				 common.modalOpen({
					title: "添加",
					url: "/STZBManage/CBGUrl/Form",
					width: "780px",
					height: "550px",
					//callBack: function (index) {
					//    var iframe = "layui-layer-iframe" + index;
					//    window.frames[iframe].submitForm();
					//}
				});
			}
			else if(obj.event === 'edit'){ //修改
				 common.modalOpen({
					title: "修改",
					url: "/STZBManage/CBGUrl/Details?Id="+id,
					width: "780px",
					height: "550px",
					//callBack: function (index) {
					//    var iframe = "layui-layer-iframe" + index;
					//    window.frames[iframe].submitForm();
					//}
				});
			}
			else if (obj.event === 'TABLE_SEARCH') { //搜索按钮
				var _that = $("#searchField");
				if (_that.hasClass("layui-hide")) {
					_that.removeClass('layui-hide');
				} else {
					_that.addClass('layui-hide');
				}
				table.resize();
			}
			return false;
		});
	});

</script>